package com.hsr.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsr.web.dto.MessageQuery;
import com.hsr.web.entity.TMenu;
import com.hsr.web.entity.TMessage;
import com.hsr.web.mapper.TMessageMapper;
import com.hsr.web.service.ITMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author tb
 * @since 2022-04-11
 */
@Service
public class TMessageServiceImpl extends ServiceImpl<TMessageMapper, TMessage> implements ITMessageService {

    @Override
    public IPage<TMessage> getList(MessageQuery query) {
        LambdaQueryWrapper<TMessage> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StringUtils.hasLength(query.getName()), TMessage::getName, query.getName())
                .like(StringUtils.hasLength(query.getContent()), TMessage::getContent, query.getContent())
                .orderByDesc(TMessage::getCreateTime);
        return page(new Page<>(query.getPage(), query.getSize()), wrapper);
    }
}
